package tech.aistar.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.dto.RankUser;
import tech.aistar.dto.Urankinfo;
import tech.aistar.entity.Level;
import tech.aistar.entity.Urank;
import tech.aistar.mapper.UrankMapper;
import tech.aistar.service.IUrankService;

import java.util.ArrayList;
import java.util.List;

@Service
public class UrankServiceImpl implements IUrankService {
    @Autowired
    private UrankMapper urankMapper;
    @Autowired
    private LevelServiceImpl levelService;
    @Autowired
    private UserServiceImpl userService;
//    @Override
//    public List<Urand> findJavaRank() {
//        return urankMapper.findJavaRank();
//    }

    @Override
    public List<Urankinfo> findScore() {
        List<Urank> javarank = urankMapper.findScore();
        List<Urankinfo> javarankinfo = new ArrayList<>();
        for (Urank u : javarank) {
            Urankinfo urankinfo = new Urankinfo();
            urankinfo.setUsAvatar(userService.findUserById(Long.valueOf(u.getRankUid())).getUsAvatar());
            urankinfo.setLevelUlevel(levelService.findlevel(u.getRankUid()));
            urankinfo.setUsNickname(userService.findusername(Long.valueOf(u.getRankUid())));
            urankinfo.setLevelUintegral(levelService.findUserlevel(String.valueOf(u.getRankUid())).getLevelUintegral());
            javarankinfo.add(urankinfo);
        }
        return javarankinfo;
    }

    @Override
    public Integer findlevel() {
        return urankMapper.findlevel();
    }

    @Override
    public List<Urank> findJavaRank() {
        return urankMapper.findJavaRank();
    }



    @Override
    public List<Urankinfo> findScore1() {
        List<Urank> pythonrank = urankMapper.findScore1();
        List<Urankinfo> pythonrankinfo = new ArrayList<>();
        for (Urank u : pythonrank) {
            Urankinfo urankinfo = new Urankinfo();
            urankinfo.setUsAvatar(userService.findUserById(Long.valueOf(u.getRankUid())).getUsAvatar());
            urankinfo.setLevelUlevel(levelService.findlevel(u.getRankUid()));
            urankinfo.setUsNickname(userService.findusername(Long.valueOf(u.getRankUid())));
            urankinfo.setLevelUintegral(levelService.findUserlevel(String.valueOf(u.getRankUid())).getLevelUintegral());
            pythonrankinfo.add(urankinfo);
        }
        return pythonrankinfo;
    }

    @Override
    public List<Urankinfo> findScore2() {
        List<Urank> crank = urankMapper.findScore2();
        List<Urankinfo> crankinfo = new ArrayList<>();
        for (Urank u : crank) {
            Urankinfo urankinfo = new Urankinfo();
            urankinfo.setUsAvatar(userService.findUserById(Long.valueOf(u.getRankUid())).getUsAvatar());
            urankinfo.setLevelUlevel(levelService.findlevel(u.getRankUid()));
            urankinfo.setUsNickname(userService.findusername(Long.valueOf(u.getRankUid())));
            urankinfo.setLevelUintegral(levelService.findUserlevel(String.valueOf(u.getRankUid())).getLevelUintegral());
            crankinfo.add(urankinfo);
        }
        return crankinfo;
    }

    @Override
    public List<Urankinfo> findScore3() {
        List<Urank> webrank = urankMapper.findScore3();
        List<Urankinfo> webrankinfo = new ArrayList<>();
        for (Urank u : webrank) {
            Urankinfo urankinfo = new Urankinfo();
            urankinfo.setUsAvatar(userService.findUserById(Long.valueOf(u.getRankUid())).getUsAvatar());
            urankinfo.setLevelUlevel(levelService.findlevel(u.getRankUid()));
            urankinfo.setUsNickname(userService.findusername(Long.valueOf(u.getRankUid())));
            urankinfo.setLevelUintegral(levelService.findUserlevel(String.valueOf(u.getRankUid())).getLevelUintegral());
            webrankinfo.add(urankinfo);
        }
        return webrankinfo;
    }

    @Override
    public List<Urankinfo> findScore4() {
        List<Urank> sqlrank = urankMapper.findScore4();
        List<Urankinfo> sqlrankinfo = new ArrayList<>();
        for (Urank u : sqlrank) {
            Urankinfo urankinfo = new Urankinfo();
            urankinfo.setUsAvatar(userService.findUserById(Long.valueOf(u.getRankUid())).getUsAvatar());
            urankinfo.setLevelUlevel(levelService.findlevel(u.getRankUid()));
            urankinfo.setUsNickname(userService.findusername(Long.valueOf(u.getRankUid())));
            urankinfo.setLevelUintegral(levelService.findUserlevel(String.valueOf(u.getRankUid())).getLevelUintegral());
            sqlrankinfo.add(urankinfo);
        }
        return sqlrankinfo;
    }

//    public List<RankUser> findRank(){
//        List<RankUser> lists = new ArrayList<>();
//        List<Urand> urands = findJavaRank();
//        System.out.println(urands);
//        for (Urand u : urands) {
//            RankUser rankUser = new RankUser();
//            Level level = levelService.findUserlevel(String.valueOf(u.getRankUid()));
//            rankUser.setUname(u.getRankUname());
//            rankUser.setRankrid(u.getRankRid());
//            rankUser.setuLevel(level.getLevelUlevel());
//            lists.add(rankUser);
//        }
//        return lists;
//    }
}
